/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.com.transportes.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import pe.com.transportes.modelo.Comentario;
import pe.com.transportes.utilitario.Fechas;

/**
 *
 * @author z3phiroth
 */
public class ComentarioDAO {

      public void insertarcomentario(Connection con,Comentario c) throws SQLException{

    String sql ="insert into comentario values (?,?,?,?,?)";
    PreparedStatement ps = con.prepareStatement(sql);


    System.out.println("codigo dao "+c.getCod_cliente());

    System.out.println("codigo coment  dao "+c.getCod_comentario());
    ps.setInt(1,c.getCod_comentario());
        ps.setInt(2, c.getCod_cliente());
        ps.setString(3, c.getTipo());
       ps.setString(4,c.getTexto());
    ps.setTimestamp(5,c.getFecha());

    ps.executeUpdate();
    }




      public Comentario buscarcomentario(Connection con,int codigo) throws SQLException{
     Comentario bean = new Comentario();
  String sql = "select * from comentario where cod_cliente=?";

        PreparedStatement ps = con.prepareStatement(sql);
        ps.setInt(1,codigo);

          ResultSet rs = ps.executeQuery();
        if(rs.next()){

      bean.setCod_comentario(rs.getInt(1));
    bean.setCod_cliente(rs.getInt(2));
    bean.setTipo(rs.getString(3));
    bean.setTexto(rs.getString(4));
    bean.setFecha(rs.getTimestamp(5));
        }
        return bean;

}






   public ArrayList<Comentario> Listacomentarios(Connection con) throws SQLException{

          ArrayList<Comentario> lista = new ArrayList<Comentario>();

  String sql = "select * from comentario";

        PreparedStatement ps = con.prepareStatement(sql);

          ResultSet rs = ps.executeQuery();
      while(rs.next()){
 Comentario bean = new Comentario();
 
       bean.setCod_comentario(rs.getInt(1));
    bean.setCod_cliente(rs.getInt(2));
    bean.setTipo(rs.getString(3));
    bean.setTexto(rs.getString(4));
    bean.setFecha(rs.getTimestamp(5));
         lista.add(bean);
        }
        return lista;


}






}
